import React from "react";
import { IdeaItem, EmptyPage, MyNavBar } from "../../../components";
import style from "./style.module.scss";
import { useAppSelector } from "../../../store/hooks";
import { useRequest } from "ahooks";
import { getAdoptIdeas } from "../../../api/my";
import { useNavigate } from "react-router-dom";

//  我的被采纳的建议 数据类型
interface AdoptIdeaRawState {
  releaseUserId: number;
  releaseUserNickName: string;
  releaseUserHeadPic: string;
  title: string;
  disease: string;
  adoptTime: number;
  content: string;
}

const Index: React.FC = () => {
  const navigate = useNavigate();
  const userId = useAppSelector((state) => state.user.userInfo.userId);
  const sessionId = useAppSelector((state) => state.user.userInfo.sessionId);
  //  查询我的被采纳的建议 接口
  const { data: adoptIdeas = [] } = useRequest(async () => {
    const resp = await getAdoptIdeas(1, 3, userId, sessionId);
    return resp.result as AdoptIdeaRawState[];
  });
  return (
    <div>
      {adoptIdeas.length === 0 ? (
        <EmptyPage
          path="/my"
          title="被采纳建议"
          desc="您暂时还没有建议被采纳！"
        ></EmptyPage>
      ) : (
        <div className={style.myIdeas}>
          <div className="navbar">
            <MyNavBar
              title="被采纳建议"
              leftArrow
              style={{ backgroundColor: "#fff", borderTop: "" }}
              onClickLeft={() => navigate("/my")}
            ></MyNavBar>
          </div>
          <div className={style.content}>
            {adoptIdeas.map((item, index) => (
              <IdeaItem item={item} key={index}></IdeaItem>
            ))}
          </div>
        </div>
      )}
    </div>
  );
};

export default Index;
